//
//  ThemManager.swift
//  MasterBoy
//
//  Created by kyson on 2024/9/20.
//

import Foundation
import UIKit

class ThemeManager {
    static let shared = ThemeManager()
    
    private init() {}
    
    // 返回动态背景颜色
    func dynamicBackgroundColor() -> UIColor {
        if #available(iOS 13.0, *) {
            return UIColor { traitCollection in
                return self.backgroundColor(for: traitCollection.userInterfaceStyle)
            }
        } else {
            // Fallback on earlier versions
            return .white
        }
    }
    
    // 返回动态背景颜色
    func dynamicForgroundColor() -> UIColor {
        if #available(iOS 13.0, *) {
            return UIColor { traitCollection in
                return self.forgroundColor(for: traitCollection.userInterfaceStyle)
            }
        } else {
            // Fallback on earlier versions
            return .white
        }
    }
    
    func dynamicSeperateLineColor() -> UIColor {
        if #available(iOS 13.0, *) {
            return UIColor { traitCollection in
                return self.seperateLineColor(for: traitCollection.userInterfaceStyle)
            }
        } else {
            // Fallback on earlier versions
            return .white
        }
    }
    
    // 返回动态文本颜色
    func dynamicTextColor() -> UIColor {
        if #available(iOS 13.0, *) {
            return UIColor { traitCollection in
                return self.textColor(for: traitCollection.userInterfaceStyle)
            }
        } else {
            // Fallback on earlier versions
            return UIColor(colorHex: 0x333333)
        }
    }
    
    // 返回背景颜色，根据用户界面风格
    private func backgroundColor(for style: UIUserInterfaceStyle) -> UIColor {
        switch style {
        case .dark:
            return UIColor(colorHex: 0x111111)
        default:
            return UIColor(colorHex: 0xededed)
        }
    }
    
    private func forgroundColor(for style: UIUserInterfaceStyle) -> UIColor {
        switch style {
        case .dark:
            return UIColor(colorHex: 0x181818)
        default:
            return .white
        }
    }
    
    // 返回文本颜色，根据用户界面风格
    private func textColor(for style: UIUserInterfaceStyle) -> UIColor {
        switch style {
        case .dark:
            return .white
        default:
            return UIColor(colorHex: 0x333333)
        }
    }
    
    private func seperateLineColor(for style: UIUserInterfaceStyle) -> UIColor {
        switch style {
        case .dark:
            return UIColor.init(colorHex: 0x252525, alpha: 0.9)
        default:
            return .lightGray.withAlphaComponent(0.9)
        }
    }
    
    // 可以添加更多动态颜色方法...
}
